/*
 * jQuery File Upload Plugin JS Example 4.6
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://creativecommons.org/licenses/MIT/
 */

/*jslint unparam: true */
/*global $ */

$(function () {
    // Initialize jQuery File Upload (Extended User Interface Version):
    //$('#file_upload').fileUploadUIX();

    // Load existing files:
    /*$.getJSON($('#file_upload').fileUploadUIX('option', 'url'), function (files) {
    var options = $('#file_upload').fileUploadUIX('option');
    options.adjustMaxNumberOfFiles(-files.length);
    $.each(files, function (index, file) {
    options.buildDownloadRow(file, options)
    .appendTo(options.downloadTable).fadeIn();
    });
    });*/
    $('#file_upload').fileUploadUI({
        uploadTable: $('#files'),
        buildUploadRow: function (files, index, handler) {
            return $('<tr><td class="file_upload_preview"><\/td>' +
                    '<td>' + files[index].name + '<\/td>' +
                    '<td class="file_upload_progress"><div><\/div><\/td>' +
                    '<td class="file_upload_cancel">' +
                    '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                    '<\/button><\/td><\/tr>');
        },
        buildDownloadRow: function (result, handler) {
            if (result.code == 200) {
                return $('<tr><td><img src="' + result.photoUrl + '" width="125" height="94" class="photoList_photo"\/><\/td><td>' + result.filename + '<\/td><td>' + result.message + '<\/td><\/tr>');
            } else {
                return $('<tr><td>No image<\/td><td>' + result.filename + '<\/td><td><div class="errorMessage">' + result.message + '</div><\/td><\/tr>');
            }
        }
    });
});